<template>
  <div class="login-box">
    <div class="login-left">
      <img src="@/assets/login-bg.webp" />
    </div>
    <div class="login-right">
      <LoginForm v-if="formType === 'login'" @forgot="forgotPassword()" @register="register()" />

      <RegisterForm v-else-if="formType === 'register'" @login="toLogin()" />

      <ForgotPasswordForm v-else-if="formType === 'forgot'" @login="toLogin()" @signUp="toCheckEmailCode()" />

      <CheckEmailCodeForm v-else-if="formType === 'checkcode'" @login="toLogin()" />
    </div>
  </div>
</template>

<script>
import LoginForm from './components/loginForm'
import RegisterForm from './components/registerForm'
import ForgotPasswordForm from './components/forgotPasswordForm'
import CheckEmailCodeForm from './components/checkEmailCodeForm'

export default {
  name: 'login',

  components: { LoginForm, RegisterForm, ForgotPasswordForm, CheckEmailCodeForm },

  data() {
    return {
      formType: 'login'
    }
  },

  mounted() {
    if (this.$route.query.type === 'req') {
      this.formType = 'register'
    }
  },

  methods: {
    forgotPassword() {
      this.formType = 'forgot'
    },

    register() {
      this.formType = 'register'
    },

    toLogin() {
      this.formType = 'login'
    },

    toCheckEmailCode() {
      this.formType = 'checkcode'
    }
  }
}
</script>
<style lang="scss" scoped>
.login-box {
  display: flex;
  align-items: center;

  .login-left {
    flex: 1;
    font-size: 0;

    img {
      width: 100%;
      height: 100vh;
    }
  }

  .login-right {
    flex: 0 0 705px;
  }
}
</style>
